/**
 * 残联申请
 * @author   zr
 * @date     2018/4/28 10:24
 */

/**
 * 删除上传的图片
 */
function deleteCover(value) {
	$("#" + value).remove();
}

define([
    'jquery',
    'baseUtils',
    'base',
    'modules/disability_base',
    'css!global/plugins/fileInput/fileinput.min.css',
    'plugins/fileInput/fileinput.min',
    'plugins/bootstrap-table/bootstrap-table',
    "plugins/bootstrap-dialog/bootstrap-dialog",
    'iCheck',
    'css!global/plugins/iCheck/icheck.min.css'
], function ($, baseUtils, base,  formUtil,iCheck) {
    base();
    // 手机号码验证
	jQuery.validator.addMethod("isMobile", function(value, element) {
		var length = value.length;
		var mobile = /^((1[3,5,8][0-9])|(14[5,7])|(17[0,6,7,8]))\d{8}$/;
		return this.optional(element) || (length == 11 && mobile.test(value));
	}, "请正确填写您的手机号码");
    // 身份证号码验证
	jQuery.validator.addMethod("isIDcard", function(value, element) {
		var length = value.length;
		var IDcard =  /^[1-9]\d{7}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}$|^[1-9]\d{5}[1-9]\d{3}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}([0-9]|X)$/;
		return this.optional(element) || (length == 18 && IDcard.test(value));
	}, "请正确填写您的身份证号码");
	
	//验证邮编
	jQuery.validator.addMethod("isPostCode", function(value, element) {
		var length = value.length;
		var postcode = /^[0-9][0-9]{5}$/;
		return this.optional(element) || (length == 6 && postcode.test(value));
	}, "请正确填写您的邮编号码");
	
    $("#disabilityInfo").validate({
    	ignore: [],
        rules: {
        	userPhoto:{
        		 required: true
        	},
        	name:{
        		 required: true
        	},
        	nation:{
        		 required: true
        	},
        	originPlace:{
        		required: true
        	},
        	culture:{
        		required: true
        	},
        	birthday:{
        		required: true
        	},
        	cardNumber:{
        		required: true,
        		isIDcard:true
        	},
        	address:{
        		required: true
        	},
           	mobile:{
        		required: true,
				// 自定义方法：校验手机号在数据库中是否存在
				// checkPhoneExist : true,
				isMobile : true
        	},
        	postcode:{
        		required: true,
        		isPostCode:true
        	},
        	guardianName:{
        		required: true
        	},
        	guardianRelation:{
        		required: true
        	},
        	guardianTel:{
        		required: true,
        		isMobile : true
        	},
        	workUnit:{
        		required: true
        	},
        	workType:{
        		required: true
        	},
        	workNature:{
        		required: true
        	},
        	checkUserPhoto:{
        		required: true
        	},
        	checkNewsPhoto:{
        		required: true
        	},
        	cancelReason:{
        		required: true
        	}
        },
        messages: {
        	userPhoto:{
        		 required: errorIcon + "您的照片不能为空"
        	},
            name: {
                required: errorIcon + "姓名不能为空"
            },
            nation:{
            	required: errorIcon + "民族不能为空"
            },
        	originPlace:{
        		required: errorIcon + "籍贯不能为空"
        	},
        	culture:{
        		required: errorIcon + "文化程度不能为空"
        	},
        	birthday:{
        		required: errorIcon + "出生日期不能为空"
        	},
        	cardNumber:{
        		required: errorIcon + "身份证号不能为空",
        		isIDcard: errorIcon + "请正确填写您的身份证号码"
        	},
        	address:{
        		required: errorIcon + "地址不能为空"
        	},
        	mobile:{
        		required: errorIcon + "联系电话不能为空",
        		isMobile: errorIcon + "请正确填写您的手机号码"
        	},
        	postcode:{
        		required: errorIcon + "邮编不能为空",
        		isPostCode:errorIcon + "请正确填写您的邮编号码",
        	},
        	guardianName:{
        		required: errorIcon + "姓名不能为空"
        	},
        	guardianRelation:{
        		required: errorIcon + "与监护人关系不能为空"
        	},
        	guardianTel:{
        		required: errorIcon + "监护人电话不能为空",
        		isMobile: errorIcon + "请正确填写您的手机号码"
        	},
        	workUnit:{
        		required: errorIcon + "工作单位不能为空"
        	},
        	workType:{
        		required: errorIcon + "职业工种不能为空"
        	},
        	workNature:{
        		required: errorIcon + "工作性质不能为空"
        	},
        	checkUserPhoto:{
        		required: errorIcon + "二寸照片不能为空"
        	},
        	checkNewsPhoto:{
        		required: errorIcon + "报纸照片不能为空"
        	},
        	cancelReason:{
        		required: errorIcon + "注销原因不能为空"
        	}	
        }
    });
		
		
    
    //执行
    return {
        /**
         * 基础
         */
        index: function () {
        	formUtil.initUpload(); //上传照片
       	 	$('#uploadModal').on('hide.bs.modal', function () {
    		 	$("#userImg").fileinput('destroy');
    		 	formUtil.initUpload();
     		})
     		$("input[name='sex']").iCheck({
				checkboxClass: 'icheckbox_square-green',
				radioClass: 'iradio_square-green',
				increaseArea: '10%' // optional
			});
       	    $("input[name='married']").iCheck({
				checkboxClass: 'icheckbox_square-green',
				radioClass: 'iradio_square-green',
				increaseArea: '10%' // optional
			});
         	$("input[name='residenceType']").iCheck({
			checkboxClass: 'icheckbox_square-green',
			radioClass: 'iradio_square-green',
			increaseArea: '10%' // optional
		   });
          
            $("#doSubmit").on('click', function () {
                var valid = $("#disabilityInfo").valid();
                if (valid) {
                    $.ajax({
                        url: "/disabilityApply/save",
                        type: 'POST',
                        data: $("#disabilityInfo").serialize(),
                        dataType: "JSON",
                        beforeSend: function () {
                            //触发ajax请求开始时执行
                            $("#doSubmit").text('提交中...');
                            $("#doSubmit").attr('disabled', 'disabled');
                        },
                        success: function (data) {
                            if (data.success) {
                                window.location.href = "/disabilityApply/people/" + data.model.id;
                            } else {
                                formUtil.msgTool.error(data.msg);
                                $("#doSubmit").removeAttr('disabled');
                            }
                        },
                        error: function (error) {
                            console.log(error);
                            formUtil.msgTool.error("服务器异常请重试");
                        }
                    });
                }
            });
        },
        /**
         * 监护人
         */
        people: function () {
            $("#doSubmit").on('click', function () {
            	
                var valid = $("#disabilityInfo").valid();
                if (valid) {
                    $.ajax({
                        url: "/disabilityApply/updatePeople",
                        type: 'POST',
                        data: $("#disabilityInfo").serialize(),
                        dataType: "JSON",
                        beforeSend: function () {
                            //触发ajax请求开始时执行
                            $("#doSubmit").text('提交中...');
                            $("#doSubmit").attr('disabled', 'disabled');
                        },
                        success: function (data) {
                            if (data.success) {
                                window.location.href = "/disabilityApply/work/" + data.model.id;
                            } else {
                            	 formUtil.msgTool.error(data.msg);
                            	 $("#doSubmit").removeAttr('disabled');
                            }
                        },
                        error: function (error) {
                            console.log(error);
                            formUtil.msgTool.error("服务器异常请重试");
                        }
                    });
                }
            });
            
            $("#back").on("click", function(obj){
            	window.location.href = "/disabilityApply/base/" + $("#id").val();
            })
        },
        
        /**
         * 工作信息
         */
        work: function () {
     		$("input[name='workWalfare']").iCheck({
				checkboxClass: 'icheckbox_square-green',
				radioClass: 'iradio_square-green',
				increaseArea: '10%' // optional
			});
            $("#doSubmit").on('click', function () {
                var valid = $("#disabilityInfo").valid();
                if (valid) {
                    $.ajax({
                        url: "/disabilityApply/updateWork",
                        type: 'POST',
                        data: $("#disabilityInfo").serialize(),
                        dataType: "JSON",
                        beforeSend: function () {
                            //触发ajax请求开始时执行
                            $("#doSubmit").text('提交中...');
                            $("#doSubmit").attr('disabled', 'disabled');
                        },
                        success: function (data) {
                            if (data.success) {
                            	formUtil.msgTool.success("提交成功");
                            	setTimeout(function () {
                            		window.location.href = "/user/transact";
                            		}, 3000);
                            } else {
                            	formUtil.msgTool.error(data.msg);
                            	$("#doSubmit").removeAttr('disabled');
                            }
                        },
                        error: function (error) {
                            console.log(error);
                            $("#messageCode").text("登录注册，请刷新页面后重试！");
                        }
                    });
                }
            });
            
            $("#back").on("click", function(obj){
            	window.location.href = "/disabilityApply/people/" + $("#id").val();
            })
        },
        
        
        view: function () {
        	$("input[name='sex']").iCheck({
				checkboxClass: 'icheckbox_square-green',
				radioClass: 'iradio_square-green',
				increaseArea: '10%' // optional
			});
       	 $("input[name='married']").iCheck({
				checkboxClass: 'icheckbox_square-green',
				radioClass: 'iradio_square-green',
				increaseArea: '10%' // optional
			});
         $("input[name='residenceType']").iCheck({
			checkboxClass: 'icheckbox_square-green',
			radioClass: 'iradio_square-green',
			increaseArea: '10%' // optional
		   });
  		$("input[name='workWalfare']").iCheck({
			checkboxClass: 'icheckbox_square-green',
			radioClass: 'iradio_square-green',
			increaseArea: '10%' // optional
		});
       },
        
        
        /**
         * 变更基本信息
         */
        changeBase:function(){
        	formUtil.initChange();
			//获取可变更残联信息列表 
			//formUtil.initSelectOption($("#applyList"), "/disabilityChange/getDisabilityListByUserId")
			
			//初始化残联datatable
		
			function operateFormatter(value, row, index) {
			    var tempCode = "";
				tempCode += '<button type="button" class="change btn btn-default btn-xs"><i class="iconfont icon-banjian"></i>&nbsp;变更&nbsp;</button>';
			    return '<div class="btn-group">' + tempCode + '</div>';
			}
			 //table当前行的响应事件
            var operateEvents = {
                'click .change': function (e, value, row) {
                	window.location.href="/disabilityChange/"+row.id;
                }
            };
			 $("#disabilityList").bootstrapTable({
                url: '/disabilityChange/getDisabilityListByUserId.json', // 接口 URL 地址
                cache: false, // 不缓存
                striped: true, // 隔行加亮
                pagination: true, // 开启分页功能
                sidePagination: 'server',//服务端分页
                sortOrder: 'desc', // 设置排序为反序 desc
                fixedColumns: true,//自动修复
                smartDisplay: false, // 智能显示 pagination 和 cardview 等
                toolbar: ".toolBar", //顶部工具菜单
                toolbarAlign: "right", //顶部工具位置
                mobileResponsive: "true", //手机模式自适应宽度（自动变成卡片模式）
                columns: [
                    {
                        field: 'rowno',
                        title: '序号',
                        formatter: function (value, row, index) {  
                            return index+1;  
                        },  
                        align: 'center'
                    }, {
                        field: 'name',
                        title: '姓名',
                        align: 'center'
                    },  {
                        field: 'createName',
                        title: '申请人',
                        align: 'center'
                    }, {
                        field: 'createTime',
                        title: '申请时间',
                        align: 'center'
                    }, {
                        field: 'action',
                        title: '操作',
                        align: 'center',
                        formatter: operateFormatter,
                        events: operateEvents
                    }
                ]
            });
			
			formUtil.initUpload(); //上传照片
       	 	$('#uploadModal').on('hide.bs.modal', function () {
    		 	$("#userImg").fileinput('destroy');
    		 	formUtil.initUpload();
     		})
     		
     		$("input[name='sex']").iCheck({
				checkboxClass: 'icheckbox_square-green',
				radioClass: 'iradio_square-green',
				increaseArea: '10%' // optional
			});
       	    $("input[name='married']").iCheck({
				checkboxClass: 'icheckbox_square-green',
				radioClass: 'iradio_square-green',
				increaseArea: '10%' // optional
			});
         	$("input[name='residenceType']").iCheck({
			checkboxClass: 'icheckbox_square-green',
			radioClass: 'iradio_square-green',
			increaseArea: '10%' // optional
		   });

            $("#doSubmit").on('click', function () {
                $.ajax({
                    url: "/disabilityChange/save",
                    method: "post",
                    dataType: "json",
                    data:$("#disabilityInfo").serialize(),
                    success: function (data) {
                        if (data.success == true) {
                        	  window.location.href = "/disabilityChange/people/" + $("#id").val();
                        } else {
                        	formUtil.msgTool.error("保存失败");	
                        }
                    },
                    error: function (data) {
                    	formUtil.msgTool.error("调用接口错误");	
                    }
                });
                
            });
        },

        
        changePeople:function(){
        	 formUtil.initChange();
        	
        	 $("#doSubmit").on('click', function () {
                 var valid = $("#disabilityInfo").valid();
                 if (!valid) return;
                 $.ajax({
                     url: "/disabilityChange/changePeople",
                     type: 'POST',
                     data: $("#disabilityInfo").serialize(),
                     dataType: "JSON",
                     beforeSend: function () {
                         //触发ajax请求开始时执行
                         $("#doSubmit").text('提交中...');
                         $("#doSubmit").attr('disabled', 'disabled');
                     },
                     success: function (data) {
                         if (data.success) {
                             window.location.href = "/disabilityChange/work/" + $("#id").val();
                         } else {
                        	 formUtil.msgTool.error(data.msg);	
                        	 $("#doSubmit").removeAttr('disabled');
                         }
                     },
                     error: function (error) {
                         console.log(error);
                         formUtil.msgTool.error("调用接口错误");	
                     }
                 });
             });
        	 
        	    $("#back").on("click", function(obj){
                	window.location.href = "/disabilityChange/base/" + $("#id").val();
                })
        },
        
        changeWork:function(){
        	 formUtil.initChange();
        		$("input[name='workWalfare']").iCheck({
    				checkboxClass: 'icheckbox_square-green',
    				radioClass: 'iradio_square-green',
    				increaseArea: '10%' // optional
    			});
         	
        	 $("#doSubmit").on('click', function () {
                 var valid = $("#disabilityInfo").valid();
                 if (!valid) return;
                 $.ajax({
                     url: "/disabilityChange/changeWork",
                     type: 'POST',
                     data: $("#disabilityInfo").serialize(),
                     dataType: "JSON",
                     beforeSend: function () {
                         //触发ajax请求开始时执行
                         $("#doSubmit").text('提交中...');
                         $("#doSubmit").attr('disabled', 'disabled');
                     },
                     success: function (data) {
                    	   if (data.success) {
                           	formUtil.msgTool.success("提交成功");
                           	setTimeout(function () {
                           		window.location.href = "/user/transact";
                           		}, 3000);
                           } else {
                           	formUtil.msgTool.error(data.msg);
                           	$("#doSubmit").removeAttr('disabled');
                           }
                     },
                     error: function (error) {
                         console.log(error);
                         formUtil.msgTool.error("调用接口错误");	
                     }
                 });
             });
        	  $("#back").on("click", function(obj){
              	window.location.href = "/disabilityChange/people/" + $("#id").val();
              })
        },
        //残联注销
        cancel:function(){
        	//初始化残联datatable
			function operateFormatter(value, row, index) {
			    var tempCode = "";
				tempCode += '<button type="button" class="cancel btn btn-default btn-xs"><i class="iconfont icon-banjian"></i>&nbsp;注销&nbsp;</button>';
			    return '<div class="btn-group">' + tempCode + '</div>';
			}
			 //table当前行的响应事件
            var operateEvents = {
                'click .cancel': function (e, value, row) {
    				//表单赋值
    				$("#applyId").val(row.id);
    				$("#showName").val(row.name);
    				$("#name").val(row.name);
    				$(".listDiv").hide();
    				$(".changDiv").show();
                }
            };
			 $("#disabilityList").bootstrapTable({
                url: '/disabilityChange/getDisabilityListByUserId', // 接口 URL 地址
                cache: false, // 不缓存
                striped: true, // 隔行加亮
                pagination: true, // 开启分页功能
                sidePagination: 'server',//服务端分页
                sortOrder: 'desc', // 设置排序为反序 desc
                fixedColumns: true,
                smartDisplay: false, // 智能显示 pagination 和 cardview 等
                toolbar: ".toolBar", //顶部工具菜单
                toolbarAlign: "right", //顶部工具位置
                mobileResponsive: "true", //手机模式自适应宽度（自动变成卡片模式）
                columns: [
                    {
                        field: 'rowno',
                        title: '序号',
                        formatter: function (value, row, index) {  
                            return index+1;  
                        },  
                        align: 'center'
                    }, {
                        field: 'name',
                        title: '姓名',
                        align: 'center'
                    },  {
                        field: 'createName',
                        title: '申请人',
                        align: 'center'
                    }, {
                        field: 'createTime',
                        title: '申请时间',
                        align: 'center'
                    }, {
                        field: 'action',
                        title: '操作',
                        align: 'center',
                        formatter: operateFormatter,
                        events: operateEvents
                    }
                ]
            });
			
            $("#doSubmit").on('click', function () {
                var valid = $("#disabilityInfo").valid();
                if (valid) {
                    $.ajax({
                        url: "/disabilityCancel/save",
                        type: 'POST',
                        data: $("#disabilityInfo").serialize(),
                        dataType: "JSON",
                        beforeSend: function () {
                            //触发ajax请求开始时执行
                            $("#doSubmit").text('提交中...');
                            $("#doSubmit").attr('disabled', 'disabled');
                        },
                        success: function (data) {
                            if (data.success) {
                            	formUtil.msgTool.success("申请成功");
                            	$(".changDiv").hide();
                				$(".listDiv").show();
                            } else {
                            	formUtil.msgTool.error(data.msg);	
                            	$("#doSubmit").removeAttr('disabled', 'disabled');
                            }
                        },
                        error: function (error) {
                            console.log(error);
                            formUtil.msgTool.error("调用接口错误");	
                        }
                    });
                }
            });
        },
        //残联注销
        reApply:function(){
        	
   
            //二寸照片
            oneUploader("#userPhotoUploader", "请选择二寸照片" , "#userPhoto-upload-error", "#userPhoto-upload-success", "userPhoto");
            
            //报纸照片
			doUploader("#newsPhotoUploader",  "请选择报纸照片", "#newsPhoto-upload-error", "#newsPhoto-upload-success", "newsPhotosList");
			
            
            function oneUploader(node, placeholder, elErrorContainer, successContainer, name) {
                return $(node).fileinput({
                    //设置语言
                    language: 'zh',
                    //上传的地址
                    uploadUrl: '/common/uploader/index',
                    //上传方式
                    method: 'post',
                    //文件筐信息
                    msgPlaceholder: placeholder,
                    //附加属性(0图片，1文件)
                    uploadExtraData: {filesType: 0},
                    //上传类型
                    allowedFileExtensions: ['jpg', 'gif', 'png', 'jpeg'],
                    //是否显示图片展示框
                    showPreview: false,
                    //是否显示上传按钮
                    showUpload: true,
                    //是否显示取消按钮
                    showCancel: false,
                    //是否显示上传输入框
                    showCaption: true,
                    //是否显示删除键
                    showRemove: false,
                    //浏览图标
                    browseIcon: '<i class="iconfont icon-wenjianjia"></i>&nbsp;',
                    //浏览样式
                    browseClass: 'btn btn-success btn-outline',
                    //上传图标
                    uploadIcon: '<i class="iconfont icon-upload"></i>&nbsp;',
                    //上传样式
                    uploadClass: 'btn btn-success btn-outline',
                    //单位为kb，(30M)如果为0表示不限制文件大小
                    maxFileSize: 10720,
                    //错误显示位置
                    elErrorContainer: elErrorContainer,
                    //错误显示位置节点样式
                    msgErrorClass: 'alert alert-block alert-danger',
                    //验证数量
                    validateInitialCount: true
                }).on("fileuploaded", function (event, data) {
                	   if (data.response !== null && data.response.status) {
                		   $("#checkUserPhoto").val(1);
                           $(successContainer).html("<div  class=\"col-sm-12\"  id=\"" + data.response.nodeId + "\"><div class=\"thumbnail uploadImageShow\" ><input type=\"hidden\" name=\"" + name + "\" value=\"" + data.response.url + "\"><a href=\"" + data.response.domain + data.response.url + "\" target='_blank'><img src=\"" + data.response.domain + data.response.url + "\"  height=\"50px\"></a><div class=\"btn btn-block btn-danger deletetCover\" onclick=\"deleteCover('" + data.response.nodeId + "')\">删除</div></div>");
                	   } else {
                           $(elErrorContainer).text(data.response.message);
                       }
                });
            }
            
            
            function doUploader(node, placeholder, elErrorContainer, successContainer, listName) {
				return $(node).fileinput({
					//设置语言
					language: 'zh',
					//上传的地址
					uploadUrl: '/common/uploader/index',
					method: 'post',
					msgPlaceholder: placeholder,
					//附加属性(0图片，1文件)
					uploadExtraData: {filesType: 0},
					//上传类型
					allowedFileExtensions: ['jpg', 'gif', 'png', 'jpeg'],
					//是否显示图片展示框
					showPreview: false,
					//是否显示上传按钮
					showUpload: true,
					showCancel: false,
					//是否显示上传输入框
					showCaption: true,
					//是否显示删除键
					showRemove: true,
					//浏览图标
					browseIcon: '<i class="iconfont icon-wenjianjia"></i>&nbsp;',
					//浏览样式
					browseClass: 'btn btn-success btn-outline',
					//上传图标
					uploadIcon: '<i class="iconfont icon-upload"></i>&nbsp;',
					//上传样式
					uploadClass: 'btn btn-success btn-outline',
					//移除图标
					removeIcon: '<i class="iconfont icon-remove"></i>&nbsp;',
					//移除样式
					removeClass: 'btn btn-info btn-outline',
					//单位为kb，(30M)如果为0表示不限制文件大小
					maxFileSize: 10720,
					//错误显示位置
					elErrorContainer: elErrorContainer,
					//错误显示位置节点样式
					msgErrorClass: 'alert alert-block alert-danger',
					//验证数量
					validateInitialCount: true
				}).on("fileuploaded", function (event, data) {
					if (data.response !== null && data.response.status) {
             		   $("#checkNewsPhoto").val(1);
						$(successContainer).append("<div class=\"col-xs-12 col-sm-6 col-md-3 mb10\" id=\"" + data.response.nodeId + "\"><div class=\"thumbnail uploadImageShow\"><input type=\"hidden\" name=\"" + listName + "\" value=\"" + data.response.url + "\"><a href=\"" + data.response.domain + data.response.url + "\" target='_blank'><img src=\"" + data.response.domain + data.response.url + "\"></a><div class=\"btn btn-block btn-danger deletetCover\" onclick=\"deleteCover('" + data.response.nodeId + "')\">删除</div></div></div>");
					} else {
						$(elErrorContainer).text(data.response.message);
					}
				});
			}

            
        	//初始化残联datatable
			function operateFormatter(value, row, index) {
			    var tempCode = "";
				tempCode += '<button type="button" class="reApply btn btn-default btn-xs"><i class="iconfont icon-banjian"></i>&nbsp;补办&nbsp;</button>';
			    return '<div class="btn-group">' + tempCode + '</div>';
			}
			 //table当前行的响应事件
            var operateEvents = {
                'click .reApply': function (e, value, row) {
                    window.location.href="/disabilityReapply/reapply/"+row.id;
                }
            };
			 $("#disabilityList").bootstrapTable({
                url: '/disabilityChange/getDisabilityListByUserId', // 接口 URL 地址
                cache: false, // 不缓存
                striped: true, // 隔行加亮
                pagination: true, // 开启分页功能
                sidePagination: 'server',//服务端分页
                sortOrder: 'desc', // 设置排序为反序 desc
                fixedColumns: true,
                smartDisplay: false, // 智能显示 pagination 和 cardview 等
                toolbar: ".toolBar", //顶部工具菜单
                toolbarAlign: "right", //顶部工具位置
                mobileResponsive: "true", //手机模式自适应宽度（自动变成卡片模式）
                columns: [
                    {
                        field: 'rowno',
                        title: '序号',
                        formatter: function (value, row, index) {  
                            return index+1;  
                        },  
                        align: 'center'
                    }, {
                        field: 'name',
                        title: '姓名',
                        align: 'center'
                    },  {
                        field: 'createName',
                        title: '申请人',
                        align: 'center'
                    }, {
                        field: 'createTime',
                        title: '申请时间',
                        align: 'center'
                    }, {
                        field: 'action',
                        title: '操作',
                        align: 'center',
                        formatter: operateFormatter,
                        events: operateEvents
                    }
                ]
            });
			
            $("#doSubmit").on('click', function () {
                var valid = $("#disabilityInfo").valid();
                if (valid) {
                    $.ajax({
                        url: "/disabilityReapply/save",
                        type: "POST",
                        data: $("#disabilityInfo").serialize(),
                        dataType: "JSON",
                        beforeSend: function () {
                            //触发ajax请求开始时执行
                            $("#doSubmit").text('提交中...');
                            $("#doSubmit").attr('disabled', 'disabled');  
                        },
                        success: function (data) {
                            if (data.success) {
                            	formUtil.msgTool.success("申请成功");
                              	setTimeout(function () {
                               		window.location.href = "/user/transact";
                               		}, 3000);
                            } else {
                            	formUtil.msgTool.error(data.msg);	
                            	$("#doSubmit").removeAttr('disabled', 'disabled');
                            }
                        },
                        error: function (error) {
                            console.log(error);
                            formUtil.msgTool.error("调用接口错误");	
                        }
                    });
                }
            });
        }
    };
});
